<div class="row">
	<div class="col-md-12">
		<ol class="breadcrumb">
			<li>
				<a href="#" onclick="toHome()">
					主页
				</a>
			</li>
			<li class="active">
				电影座位列表
			</li>
		</ol>
	</div>
</div>
<form role="form" class="form-horizontal">
	<div class="row page-cont">
		<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 cont-top">
			<div class="panel panel-white">
				<div class="panel-heading">
					<h4 class="panel-title">
						<span class="title-text">检索电影座位</span>
					</h4>
					<div class="panel-tools">
						<div class="dropdown">
							<a data-toggle="dropdown" class="btn btn-xs dropdown-toggle btn-transparent-grey">
								<i class="fa fa-cog"></i>
							</a>
							<ul class="dropdown-menu dropdown-light pull-right" role="menu">
								<li>
									<a class="panel-collapse collapses" href="#"><i class="fa fa-angle-up"></i> <span>折叠</span> </a>
								</li>
								<li>
									<a class="panel-expand" href="#">
										<i class="fa fa-expand"></i> <span>全屏</span>
									</a>
								</li>
							</ul>
						</div>
						<a class="btn btn-xs btn-link panel-close" href="#">
							<i class="fa fa-times"></i>
						</a>
					</div>
				</div>
				<div class="panel-body">
					<div class="form-group panel-cont">
					    <label class="col-sm-2 control-label">影片名称</label>
					    <div class="col-sm-4">
					      <input type="text" class="form-control" id="movieName" />
					    </div>
				  	</div>
					<!-- <div class="form-group panel-cont">
					    <label class="col-sm-2 control-label">状态</label>
					    <div class="col-sm-4">
					    	<select name="">
					    		<option value="">全部</option>
					    		<option value="">启用</option>
					    		<option value="">关闭</option>
					    	</select>
					    </div>
				  	</div>	
					<div class="form-group panel-cont">
					    <label for="startDate" class="col-sm-2 control-label">开始时间</label>
					    <div class="col-sm-2 selectDate">
					   		<input type='text' readonly="readonly" class='form-control selectData' id='startDate' name='date' value='' />
					   		<i class="fa fa-calendar"></i>  
					    </div>
					    <label for="endDate" class="col-sm-2 control-label">结束时间</label>
					    <div class="col-sm-2 selectDate">
					    	<input type='text' readonly="readonly" class='form-control selectData' id='endDate' name='date' value='' />
					    	<i class="fa fa-calendar"></i>
					    </div>
					    <span class="col-sm-4 tips">
					    	<i class="fa fa-info-circle"></i>
					    	请选择创建日期的区间
					    </span>
				  	</div>			 -->	  		
				  	<div class="form-group">
				  		<div class="col-sm-5 col-sm-offset-5">
				  			<button type="button" class="btn btn-primary query-btn">查询</button>
				  			<button type="reset" class="btn">重置</button>
				  		</div>
				  	</div>
				</div>
			</div>
		</div>
		<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 cont-bottom">
			<div class="panel panel-white">
				<div class="panel-heading">
					<h4 class="panel-title">
						<span class="title-text">电影座位列表</span>
					</h4>
					<div class="panel-tools">
						<div class="dropdown">
							<a data-toggle="dropdown" class="btn btn-xs dropdown-toggle btn-transparent-grey">
								<i class="fa fa-cog"></i>
							</a>
							<ul class="dropdown-menu dropdown-light pull-right" role="menu">
								<li>
									<a class="panel-collapse collapses" href="#"><i class="fa fa-angle-up"></i> <span>折叠</span> </a>
								</li>
								<li>
									<a class="panel-expand" href="#">
										<i class="fa fa-expand"></i> <span>全屏</span>
									</a>
								</li>
							</ul>
						</div>
						<a class="btn btn-xs btn-link panel-close" href="#">
							<i class="fa fa-times"></i>
						</a>
					</div>
				</div>
				<div class="row table-btn">
					<div class="col-sm-12">
						<button type="button" class="btn btn-success add-btn">单一新增&nbsp;<i class="fa fa-plus"></i></button>
						<button type="button" class="btn btn-success all-add-btn">全量新增&nbsp;<i class="fa fa-plus"></i></button>
					</div>
				</div>				
				<div class="panel-body table-body">
					<table class="table table-bordered table-hover">
						<thead>
							<tr>
								<th class="hidden-xs">ID</th>
								<th class="hidden-xs">影片名称</th>
								<th class="hidden-xs">影院名称</th>
								<th class="hidden-xs">排期时间</th>
								<th class="hidden-xs">创建时间</th>
								<th class="hidden-xs">更新时间</th>
								<th class="hidden-xs">状态</th>
								<th class="hidden-xs">操作</th>
							</tr>
						</thead>
						<tbody>

						</tbody>
					</table>
				</div>
			</div>
		</div>
	</div>
</form>
<script>
	/*************************************变量******************************************/
	var pageNo = 1;     // 第几页
	var pageSize = 10;  // 每页几条
	var totalPage;      // 总页数
	var totalData;      // 总条数
	var username = GetQueryString("username");    // 用户姓名
	var token = MXCookie.get("token",token);      // 登陆token  	

	/*************************************事件******************************************/
	datePicker($("#startDate"));  // 开始时间
	datePicker($("#endDate"));    // 结束时间	

	// 单一新增
	toOperat($(".add-btn"),"view/movieSeat/add-movie-seat.html");

	// 全量新增
	toOperat($(".all-add-btn"),"view/movieSeat/all-add-seat.html");

    // 不删除
	$("body").on("click",".ask-no",function(){
		$(".ask-alert").fadeOut();	        	
    });		

    // 关闭弹框
	$("body").on("click",".close-icon",function(){
		$(".ask-alert").fadeOut();	        	
    });		

    // 查询
    $(".query-btn").click(function(){
		getList();
		// 分页
		pageSetGet();		
    });

	/*************************************函数******************************************/
	// 确定删除
	function dialogyYesBtn () {
		var picId = $(".ask-alert").attr("data-id");
		var index = $(".ask-alert").attr("data-index");
    	deleteList(picId,index);
	}

	// 获取列表
	function getList(){
		$("tbody").html("");
		$.ajax({
			url: localStorage.grobalUrl + "/seat/seatImgList",
			type: "post",
			async:false,
			data:{
				username: username,
				token: token,
				pageSize: pageSize,
				pageNumber: pageNo,
				filmName: $("#movieName").val()
			},
			success: function(data){
				console.log(data);
				var str = '<tr align="center">'+
								'<td class="seat-id"></td>'+
								'<td class="movie-name"></td>'+
								'<td class="film-name"></td>'+
								'<td class="schedule-time"></td>'+
								'<td class="create-time"></td>'+
								'<td class="update-time"></td>'+
								'<td class="seat-status"></td>'+
								'<td>'+
									'<button type="button" class="btn btn-dark-yellow check-btn">查看<i class="fa fa-eye"></i></button>'+
									'<button type="button" class="btn btn-green edit-btn">编辑<i class="fa fa-edit"></i></button>'+
									'<button type="button" class="btn btn-red delete-btn">删除<i class="fa fa-trash-o"></i></button>'+
								'</td>'+
							'</tr>';
				if(data.seats){
					totalPage =  data.seats.totalPage;
					totalData = data.seats.totalRow;
					if(data.seats.list.length == "0"){
						$("tbody").append('<tr align="center"><td colspan="8">暂无数据</td></tr>');
					}
					for(var i = 0; i < data.seats.list.length; i ++){
						$("tbody").append(str);
						var listVal = (data.seats.list)[i];
						$(".seat-id").eq(i).text(listVal.id);
						$(".movie-name").eq(i).text(listVal.film_name);
						$(".film-name").eq(i).text(listVal.cinema_name);
						$(".schedule-time").eq(i).text(listVal.schedule_name);
						$(".create-time").eq(i).text(listVal.create_time);
						$(".update-time").eq(i).text(listVal.update_time);
						if(listVal.status == "ENABLE"){
							$(".seat-status").eq(i).text("启用");
						}else if(listVal.status == "DISABLE"){
							$(".seat-status").eq(i).text("关闭");
						}
					}

					// 查看
					jumpTo($(".check-btn"),'view/movieSeat/seat-view.html');

					// 编辑
					jumpTo($(".edit-btn"),'view/movieSeat/seat-edit.html');

					// 删除按钮
			        $(".delete-btn").click(function(){
			            var index = $(".delete-btn").index(this);
						var picId = $(".seat-id").eq(index).text();
			            askAlert("是否要删除");
			            $(".ask-alert").attr("data-id",picId).attr("data-index",index);
			        });

			        		
				}else if(data.errCode == "00005"){
					tips("请重新登陆");
					setTimeout(function(){
						window.location.href = "login_login.html";
					},500);
				}else{
				  $("tbody").append("<tr><td align='center' colspan='8'>暂无数据</td></tr>");
				}				
			},
			error: function(err){
				console.log(err);
			}
		});
	}
	getList();

	// 分页
	pageSetGet();

	// 跳转（查看/生成优惠券）
	function jumpTo(tag,pageUrl){
		tag.click(function(){
	        var index = tag.index(this);
	        seatId = $(".seat-id").eq(index).text();
	        $(".pageAdd").attr("data-id",seatId);
	        url = pageUrl;
	        getPage(url); 
	    });		
	}

	// 删除
	function deleteList(picId,index){
		$.ajax({
			url: localStorage.grobalUrl + "/seat/deletePic",
			type: "post",
			data: {
				username: username,
				token: token,
				picId: picId
			},
			success: function(data){
				console.log(data);
				if(data.errCode == "00000"){
					$(".delete-btn").eq(index).parent().parent().remove();
					$(".ask-alert").fadeOut();
					tips("已删除");
				}else if(data.errCode == "00005"){
					tips("请重新登陆");
					setTimeout(function(){
						window.location.href = "login_login.html";
					},500);					
				}else{
					tips("删除失败");
					$(".ask-alert").fadeOut();
				}				
			},
			error: function(err){
				console.log(err);
			}

		});
	}	

</script>
